<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>_${customer.customerName}_上架</title>
<script type="text/javascript">

  $(function() {
       //如果上架已经完成，隐藏操作按钮
	   var status='${task.status}';
	   if(status!='token' && status!='doing'){
	      $("button").hide();   
	   }
  });
  
  function keydown(){
	  $("#msg").html("");
  }
  
  function boxCodeChange(){
	  $("#txt_stockCode").val('');
	  $("#txt_stockCode").focus();
  }
  
  function stockCodeChange(){
	  var boxCode=$("#txt_boxCode").val().trim();
	  var stockCode=$("#txt_stockCode").val().trim();
	  
	  if(boxCode.length==0){
		  $("#msg").css("color","red");
		  $("#msg").html("请录入/扫描箱编码!");
		  $("#txt_boxCode").focus();
	  }
	  
	  if(stockCode.length==0){
		  $("#msg").css("color","red");
		  $("#msg").html("请录入/扫描库位编码!");
		  $("#txt_stockCode").select();
		  $("#txt_stockCode").focus();
	  }
	  
	  var uptaskCode='${task.taskCode}';
	  
      $.ajax({
			type:'post',
			url:'${ctx}/v2_instorageUp/ajaxUp_box',
			data:{
				uptaskCode:uptaskCode,
				boxCode:boxCode,
				stockCode:stockCode
			},
			dataType:'json',
			success:function(data) {
				var msg=data.msg;
			    if( msg=='continue'){
				    $("#msg").css("color","green");
		            $("#msg").html("上架成功.");
		            
		            $("#txt_boxCode").val('');
		            $("#txt_stockCode").val('');
		            $("#txt_boxCode").focus();
		            $("#upStatus_"+boxCode).html("<font color=green>已上架</font>");
		            
			    }
			    else if(msg=='finishing'){
			        $("#msg").css("color","green");
		            $("#msg").html("上架成功.");
		            $("#upStatus_"+boxCode).html("<font color=green>已上架</font>");
		            
		            window.alert("完成上架！！请按“确定”继续。"); 
				    location.href='${ctx}/v2_instorageUp/toUpTaskListPage';
		            
			    }
			    else if(msg=='uped'){
			        $("#msg").css("color","red");
		            $("#msg").html("已上架！");
		            
		            $("#txt_boxCode").val('');
		            $("#txt_stockCode").val('');
		            $("#txt_boxCode").focus();
			    }
			    else if(msg=='S009'){
			        $("#msg").css("color","red");
		            $("#msg").html("入库单已取消");
		            
		            $("#txt_boxCode").val('');
		            $("#txt_stockCode").val('');
		            $("#txt_boxCode").focus();
			    }
			    else{
			        $("#msg").css("color","red");
		            $("#msg").html("验证不成功！");
		            
		            $("#txt_boxCode").val('');
		            $("#txt_stockCode").val('');
		            $("#txt_boxCode").focus();
			    }
			},
			error:function() {
				alert("网络繁忙，请稍后重试...");
			}
	   });
  }
  
</script>
</head>

<body>
<section class="content">
	<table id="contentTable" class="table  table-bordered table-condensed">
	    <thead>
			<th style="vertical-align: middle; color: white; " colspan="13" bgcolor="#3c8dbc"><i class="fa fa-barcode"/>  扫描上架（整箱）</th>
		</thead>
		
		<tr>
		    <td > 
		       <span style="margin-left: 10px;">箱编码:</span>
		       <input id="txt_boxCode" type="text" onchange="boxCodeChange();"  onkeydown="keydown();"/>
		       
		       <span style="margin-left: 10px;">位编码:</span>
		       <input id="txt_stockCode" type="text" onchange="stockCodeChange();"/>
		       
		       <span style="margin-left:12px; margin-top: 10px; color: red;font-weight: bold;" id="msg"></span>
		       
		    </td>
		</tr>
		
	</table>
	
	
	<!-- 整箱数据 -->
	<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
		<thead>
			<th style="vertical-align: middle; color: white; " colspan="13" bgcolor="#3c8dbc"><i class="fa fa-th-list"/>  商品数据</th>
		</thead>
		<thead><tr>
		        <th style="width: 150px;">箱编码</th>
			    <th style="width: 150px;">SKU</th>
			    <th style="width: 150px;">数量/箱</th>
			    <th>是否上架</th>
			</tr></thead>
		<tbody id="boxItem">
		<c:forEach items="${itemList}" var="t" varStatus="i">
			<tr id="tr_${t.boxCode}">
			   <td >${t.boxCode}</td>
			   <td>${t.sku}</td>
			   <td>${t.num}</td>
			   <td id="upStatus_${t.boxCode}">
			       <c:if test="${t.upStatus eq 'up' }"><font color=green>已上架</font></c:if>
			       <c:if test="${t.upStatus eq 'unup' }"><font color=red>未上架</font></c:if>
			   </td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	
</section>	
</body>
</html>
